package com.ap.core.business.message.response.translators.impl;

import com.ap.core.business.message.domain.translators.BindingMetaData;
import com.ap.core.business.message.response.translators.ResponseMetaData;
import com.ap.core.business.message.response.translators.ResponseTranslator;
import com.ap.core.business.message.response.translators.listener.ResponseListener;
import com.ap.core.common.types.ParameterName;
import com.ap.core.cxf.jaxb.common.ActivationStatus;
import com.ap.core.cxf.jaxb.common.UpdateStatus;
import com.ap.core.cxf.jaxb.manageconsumer.ConsumerRegistResponseType;
import com.ap.core.dao.ApParameterDao;
import com.ap.core.message.manageconsumer.info.RequestRegisterConsumerTypeInfo;
import com.ap.core.message.manageconsumer.info.ResponseRegisterConsumerTypeInfo;

/**
 * implementation class for {@link com.ap.core.business.message.response.translators.ResponseTranslator} to populate {@link com.ap.core.cxf.jaxb.manageconsumer.ConsumerRegistResponseType}  in response object
 */
public class ResponseRegisterConsumerTranslator implements ResponseTranslator<RequestRegisterConsumerTypeInfo, ResponseRegisterConsumerTypeInfo> {

    private ApParameterDao apParameterDao;

    /**
     * {@inheritDoc}
     */
    @Override
    public void populateResponse(RequestRegisterConsumerTypeInfo request, ResponseRegisterConsumerTypeInfo response, BindingMetaData bindingMetaData, ResponseMetaData responseMetaData, ResponseListener responseListener) {

        final ConsumerRegistResponseType consumerRegistResponseType  = new ConsumerRegistResponseType();
        consumerRegistResponseType.setFIId(request.getRegistrationInfo().getFIId());
        consumerRegistResponseType.setFIConsumerId(request.getRegistrationInfo().getFIConsumerId());
        consumerRegistResponseType.setUpdateStatus(UpdateStatus.SUCCESSFUL);
        consumerRegistResponseType.setActivationStatus(ActivationStatus.REGISTERED);
        consumerRegistResponseType.setConsumerPortalUrl(apParameterDao.findByKey(ParameterName.AP_CONSUMER_PORTAL).getParameterValue());

        response.setConsumerRegistResponse(consumerRegistResponseType);
        responseListener.onMessageResponse(response);

    }

    public void setApParameterDao(ApParameterDao apParameterDao) {
        this.apParameterDao = apParameterDao;
    }
}
